// 导入三级联动的接口函数
import { reqCategoryList } from '@/api/index'
const state = {
  // state中的初始值要和服务器返回的类型保持一致
  categoryList: []
}
const mutations = {
  CATEGORYLIST(state, categoryList) {
    state.categoryList = categoryList
  }
}
const getters = {
}
const actions = {
  // 首页派发的‘getCategoryList’事件
  async getCategoryList({ commit }) {
    // 发送请求
    const result = await reqCategoryList()
    if (result.code === 200) {
    //  请求成功，派发一个mutation,并将返回的数据传递过去
      commit('CATEGORYLIST', result.data)
    }
  }
}

export default {
  state,
  mutations,
  getters,
  actions
}
